﻿using System.Web.UI;
using HNAlbum.WebControl;

namespace HNAlbum.Class
{
    /// <summary>
    /// Base class for all pages
    /// </summary>
    public abstract class BasePage : Page
    {
        /// <summary>
        /// The master page
        /// </summary>
        protected HNAlbum CustomMasterPage
        {
            get { return (HNAlbum)Master; }
        }

        /// <summary>
        /// Set global page message
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type"></param>
        protected void SetPageMessage(string msg, PageMessage.MessageType type)
        {
            CustomMasterPage.SetPageMessage(msg, type);
        }

        /// <summary>
        /// Register a stylesheet file
        /// </summary>
        /// <param name="fileName"></param>
        protected void RegisterCSS(string fileName)
        {
            CustomMasterPage.RegisterCSS(fileName);
        }

        /// <summary>
        /// Register default page JS files
        /// </summary>
        /// <param name="fileName"></param>
        protected void RegisterJS(string fileName)
        {
            CustomMasterPage.RegisterJS(fileName, "Page");
        }

        /// <summary>
        /// Register a JS file on sub path of script folder
        /// </summary>
        /// <param name="fileName"></param>
        /// <param name="folder"></param>
        protected void RegisterJS(string fileName, string folder)
        {
            CustomMasterPage.RegisterJS(fileName, folder);
        }

        /// <summary>
        /// Application physical path
        /// </summary>
        protected string AppPhysicalPath
        {
            get { return Server.MapPath("~"); }
        }

        /// <summary>
        /// If logged in user is a guest
        /// </summary>
        /// <returns></returns>
        protected bool IsGuest
        {
            get { return (CustomMasterPage.SessionCollection.User.CurrentUser == null && CustomMasterPage.SessionCollection.User.IsAuthenticated == true); }
        }
    }
}